﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;
namespace WebSite.UserSetting
{
    public partial class MessageReply : System.Web.UI.Page
    {
        private string touserid = "";
        private string source = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            touserid = Request.QueryString["touserid"] + "";
            source = Request.QueryString["source"] + "";//来源
            if (!Page.IsPostBack)
            {
                LoadContent();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Users uinfo = UserBase.GetCurrentUser();

            Message minfo = new Message();
            MessageHelper mhelper = new MessageHelper();
            minfo.FromUsersID = uinfo.ID;
            minfo.FromNickName = uinfo.NickName;
            minfo.ToUsersID = hidToUserID.Value;
            minfo.Flag = 0;
            minfo.Status = 0;
            minfo.MessageContent = txtContent.Text.Trim();

            mhelper.AddMessage(minfo);

            if (string.IsNullOrEmpty(source))
            {
                Tools.AlertAndRedirect("短消息回复成功", "MessageList.aspx");
                return;
            }
            else if(source=="companylist")
            {
                Tools.AlertAndRedirect("短消息回复成功", "../Company/CompanyList.aspx");
                return;
            }
        }

        #region 加载内容
        private void LoadContent()
        {
            Users uinfo = new Users();
            UsersHelper uhelper = new UsersHelper();
            uinfo = uhelper.GetUsers(touserid);
            litNickName.Text = uinfo.NickName;
            hidToUserID.Value = uinfo.ID;
        }
        #endregion

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(source))
            {
                Response.Redirect("MessageList.aspx");
            }
            else if (source == "companylist")
            {
                Response.Redirect("../Company/CompanyList.aspx");
            }
        }
    }
}